//:C16:IterStackTemplateTest.cpp
// {L} fibonacci
#include "fibonacci.h"
#include "IterStackTemplate.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main(void)
{
    StackTemplate<int> is;
    for(int i = 0; i < 20; i++)
    {
        is.push(fibonacci(i));
    }
    // Traverse with an iterator:
    cout << "Traverse the whole StackTemplate\n";
    StackTemplate<int>::iterator it = is.begin();
    while(it != is.end())
    {
        cout << it++ << endl;
    }
    cout << "Traverse a portion\n";
    StackTemplate<int>::iterator
        start = is.begin(), end = is.end();
    start += 5, end +=15;
    cout << "start = " << start << endl;
    cout << "end = " << end << endl;
    while(start != end)
    {
        cout << start++ << endl;
    }
    ifstream in("IterStackTemplateTest.cpp");
    assure(in, "IterStackTemplateTest.cpp");
    string line;
    StackTemplate<string> strings;
    while(getline(in, line))
    {
        strings.push(line);
    }
    StackTemplate<string>::iterator
        sb = strings.begin(), se = strings.end();
    while(sb != se)
    {
        cout << sb++ << endl;
    }
}
